/**
 * Copyright (c) 2013-Now http://dreamcode123321.com All rights reserved.
 */
package com.jeesite.modules.ab.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.utils.excel.ExcelExport;
import com.jeesite.modules.ab.entity.WeatherInfo;
import com.jeesite.modules.ab.utils.WeatherUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.ab.entity.AbTemp;
import com.jeesite.modules.ab.service.AbTempService;

import java.util.List;

/**
 * ab_tempController
 * @author dreamcode
 * @version 2020-06-20
 */
@Controller
@RequestMapping(value = "${adminPath}/ab/abTemp")
public class AbTempController extends BaseController {

	@Autowired
	private AbTempService abTempService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public AbTemp get(String id, boolean isNewRecord) {
		return abTempService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequestMapping(value = {"list", ""})
	public String list(AbTemp abTemp, Model model) {
		model.addAttribute("abTemp", abTemp);
		return "modules/ab/abTempList";
	}

	/**
	 * 导出用户数据
	 */
	@RequestMapping
			(value = "exportData")
	public void exportData(AbTemp abTemp, HttpServletResponse response) {
		List<AbTemp> list = abTempService.findList(abTemp);
		String fileName = "用户数据" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
		try(ExcelExport ee = new ExcelExport("用户数据", AbTemp.class)){
			ee.setDataList(list).write(response, fileName);
		}
	}

	/**
	 * ditu
	 */
	@RequestMapping(value = {"ditu", ""})
	public String ditu(AbTemp abTemp, Model model) {
		WeatherInfo weatherInfo = WeatherUtils.GetWeather(WeatherUtils.GetWeatherData("101010100 "));
		abTemp.setOutTemp(new Double(weatherInfo.getTemperature()));
		model.addAttribute("abTemp", abTemp);

		return "modules/ab/ditu";
	}


	/**
	 * ditu
	 */
	@RequestMapping(value = {"city", ""})
	public String city(AbTemp abTemp, Model model) {
		model.addAttribute("abTemp", abTemp);
		return "modules/ab/city";
	}

	/**
	 * ditu
	 */
	@RequestMapping(value = {"district", ""})
	public String district(AbTemp abTemp, Model model) {
		model.addAttribute("abTemp", abTemp);
		return "modules/ab/district";
	}

	/**
	 * dynamictemp_full
	 */
	@RequestMapping(value = {"dynamictemp_full", ""})
	public String dynamictemp_full(AbTemp abTemp, Model model) {
		model.addAttribute("abTemp", abTemp);
		return "modules/ab/dynamictemp_full";
	}

	/**
	 * jieshao
	 */
	@RequestMapping(value = {"jieshao", ""})
	public String jieshao(AbTemp abTemp, Model model) {
		model.addAttribute("abTemp", abTemp);
		return "modules/ab/jieshao";
	}

	/**
	 * shuoming
	 */
	@RequestMapping(value = {"shuoming", ""})
	public String shuoming(AbTemp abTemp, Model model) {
		model.addAttribute("abTemp", abTemp);
		return "modules/ab/shuoming";
	}

	/**
	 * weihu
	 */
	@RequestMapping(value = {"weihu", ""})
	public String weihu(AbTemp abTemp, Model model) {
		model.addAttribute("abTemp", abTemp);
		return "modules/ab/weihu";
	}


	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<AbTemp> listData(AbTemp abTemp, HttpServletRequest request, HttpServletResponse response) {
		abTemp.setPage(new Page<>(request, response));
		Page<AbTemp> page = abTempService.findPage(abTemp);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("ab:abTemp:edit")
	@RequestMapping(value = "form")
	public String form(AbTemp abTemp, Model model) {
		model.addAttribute("abTemp", abTemp);
		return "modules/ab/abTempForm";
	}

	/**
	 * 保存ab_temp
	 */
	@RequiresPermissions("ab:abTemp:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated AbTemp abTemp) {
		abTempService.save(abTemp);
		return renderResult(Global.TRUE, text("保存ab_temp成功！"));
	}
	
	/**
	 * 删除ab_temp
	 */
	@RequiresPermissions("ab:abTemp:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(AbTemp abTemp) {
		abTempService.delete(abTemp);
		return renderResult(Global.TRUE, text("删除ab_temp成功！"));
	}
	
}